<?php
/**
 * Created by PhpStorm.
 * User: 郑好
 * Date: 2019/3/8
 * Time: 下午4:27
 */

namespace app\common;

class Uuid
{
    use InstanceTrait;

    /**
     * @param       string $suffix
     * @return      string
     * @description uuid生成
     */
    public function create($suffix = "")
    {
        $uid = uniqid(mt_rand(), true);
        $data = '';
        $data .= $_SERVER['REQUEST_TIME'];
        $data .= $_SERVER['HTTP_USER_AGENT'];
        $data .= $_SERVER['REQUEST_URI'];
        $data .= $_SERVER['REMOTE_ADDR'];
        $data .= $_SERVER['REMOTE_PORT'];
        $data .= mt_rand();
        $hash = hash('md5', $uid . time() . md5($data));
        return $hash.$suffix;
    }

    /**
     * @param       int $num
     * @return      string
     * @description 手机验证码生成
     */
    public function makeTelCode($num = 4)
    {
        $code = "";
        for ($i =1; $i<=$num; $i++) {
            $code .= rand(0, 9);
        }
        return $code;
    }
}
